package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-03 20:22
 **/
public class LeetCode141 {

    public boolean hasCycle(ListNode head) {
        //0个节点或1个节点必没有环
        if (head == null || head.next == null) {
            return false;
        }

        ListNode fast = head;
        ListNode slow = head;
        do {
            fast = fast.next.next;
            slow = slow.next;
        } while (fast != null && fast.next != null && fast != slow);

        if (fast == null || fast.next == null) {
            return false;
        }

        return true;
    }

}
